package com.yu.boot.admin.service;

import com.yu.boot.admin.model.User;
import com.lhy.commonweb.service.AbstractService;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.entity.Example;

import javax.xml.crypto.dsig.keyinfo.KeyName;
import java.util.List;

@Service
public class UserService extends AbstractService<User, Integer> {

    public UserService(@Qualifier("userMapper") Mapper<User> mapper) {
        super(mapper);
    }

    public User getUserByName(String name){
        Example e = new Example(User.class);
        e.createCriteria().andEqualTo(User.FieldEnum.NAME.javaFieldName(),name);
        List<User> users = this.mapper.selectByExample(e);
        if (users.isEmpty()){
            return null;
        }else{
            return users.get(0);
        }
    }

}
